var webpack             = require('webpack');
var path                = require('path');
var node_modules_dir    = path.join(__dirname, 'node_modules');
var TransferWebpackPlugin = require('transfer-webpack-plugin');
var ExtractTextPlugin   = require("extract-text-webpack-plugin");
//var es3ifyPlugin = require('es3ify-webpack-plugin');


//const targetUrl = 'http://127.0.0.1:3000/';//本地
const targetUrl = 'http://ichahar.cn/';//本地
//const targetUrl = 'http://192.168.1.146';
const copyForm = './app';
const copyTo = './assets';


var config = {
    entry:{
        'index': ['./app/index.js', 'babel-polyfill', 'whatwg-fetch', 'fetch-polyfill'],
    },
    externals:{
        '_':'window.localStorage',
    },
    output: {
        path            : __dirname +'/dist/',
        filename        : 'js/[name].js'
    },
    resolve: {
        alias: {
            'action':path.join(__dirname, 'app/actions'),
            'components':path.join(__dirname, 'app/components'),
            'css':path.join(__dirname, 'app/css'),
            'common':path.join(__dirname, 'app/common'),
            'middlewares':path.join(__dirname, 'app/middlewares'),
            'jQuery': path.join(__dirname, 'app/common/jquery-vendor.js')
        }
    },
    module: {
        rules: [
            {test: /\.css$/, use:['style-loader','css-loader']},
            {test: /\.less$/, use:['style-loader','css-loader','less-loader']},
            {test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                  limit: 10000,
                  name: 'resource/[name].[ext]'
                }
            },
            {test: /\.string$/, use: 'html-loader' },
            {
                test: /\.js?$/,
                exclude: /(node_modules|bower_components)/,
                use: 'babel-loader'
            },
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: 'babel-loader?presets[]=react&presets[]=es2015',
            },
            
        ]
    },
    devServer: {
        inline: true,
        port: 80,
        host: 'localhost',
        historyApiFallback: true,
        noInfo: false,
        stats: 'minimal',
        clientLogLevel: 'none',
        proxy: {
            '/wx/*':{
              target: targetUrl,
              changeOrigin: true
            }
         }
    },
    plugins: 
    [
        //拷贝文件
        new TransferWebpackPlugin([
            //index.html
            { from: './app/index-html', to:'./' },

            //公用类库
            { from:path.join(copyForm, '/common'), to:'./common' },

            //图片
            { from:path.join(copyForm, '/images'), to:'./image' },
        ])

    ]

};

module.exports = config;

